package cn.easyutil.veteran.core.utils;

import cn.easyutil.veteran.core.error.CommonException;
import cn.easyutil.veteran.core.error.ErrorCodeDefinition;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;

/**
 * 断言
 */
public class AssertUtil {

    public static void isEmpty(String s,String errorMsg){
        isTrue(StringUtils.isBlank(s),errorMsg);
    }

    public static void isEmpty(String s, ErrorCodeDefinition e){
        isTrue(StringUtils.isBlank(s),e);
    }

    public static void isNotEmpty(String s,String errorMsg){
        isTrue(StringUtils.isNotBlank(s),errorMsg);
    }

    public static void isNotEmpty(String s, ErrorCodeDefinition e){
        isTrue(StringUtils.isNotBlank(s),e);
    }

    public static void isNull(Object object,String errorMsg){
        isTrue(object == null,errorMsg);
    }

    public static void isNull(Object object,ErrorCodeDefinition e){
        isTrue(object == null,e);
    }

    public static void isNotNull(Object object,String errorMsg){
        isTrue(object != null,errorMsg);
    }

    public static void isNotNull(Object object,ErrorCodeDefinition e){
        isTrue(object != null,e);
    }

    public static void isFalse(boolean boo,String errorMsg){
        isTrue(!boo,errorMsg);
    }

    public static void isFalse(boolean boo, ErrorCodeDefinition e){
        isTrue(!boo,e);
    }

    public static void isTrue(boolean boo,String errorMsg){
        if(boo){
            throw new CommonException(errorMsg);
        }
    }

    public static void isTrue(boolean boo, ErrorCodeDefinition e){
        if(boo){
            throw new CommonException(e);
        }
    }
}
